package com.archgeek.bigdata;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @author pizhihui
 * @date 2022-02-25 15:14
 */
public class CuratorClient {

    static CuratorFramework getClient(String zkAddress) {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 6);
        CuratorFramework client = CuratorFrameworkFactory.builder()
                .connectString(zkAddress)
                .retryPolicy(retryPolicy)
                .sessionTimeoutMs(6000)
                .connectionTimeoutMs(3000)
                //.namespace("kyuubi-ts-heartbeat")
                .build();
//        client.getConnectionStateListenable().addListener(new ConnectionStateListener() {
//            @Override
//            public void stateChanged(CuratorFramework client, ConnectionState newState) {
//                logger.warn("zookeeper leader client state|" + newState.name());
//            }
//        });
        client.start();
        return client;
    }

}
